<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>表格组件 | CatchAdmin 官网</title>
    <meta name="description" content="">
    <meta name="generator" content="VuePress 1.8.2">
    <style>a[title="站长统计"]{display:none}</style>
    <script data-ad-client="ca-pub-1505209242532150" async="true" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <script src="https://v1.cnzz.com/z_stat.php?id=1279921342&amp;web_id=1279921342"></script>
    <meta name="description" content="基于 Thinkphp & Vue 开发的后台管理框架">
    <meta name="keywords" content="catchadmin, 后台管理, 前后端分离, thinkphp后台管理框架, thinkphp前后端分离框架,php, elementui">
    <link rel="preload" href="/assets/css/0.styles.6834c255.css" as="style"><link rel="preload" href="/assets/js/app.d0396f44.js" as="script"><link rel="preload" href="/assets/js/2.1cef47df.js" as="script"><link rel="preload" href="/assets/js/32.7b8e9cfe.js" as="script"><link rel="prefetch" href="/assets/js/10.483f2013.js"><link rel="prefetch" href="/assets/js/11.981d4461.js"><link rel="prefetch" href="/assets/js/12.95d2c383.js"><link rel="prefetch" href="/assets/js/13.061c2fe0.js"><link rel="prefetch" href="/assets/js/14.ec2753db.js"><link rel="prefetch" href="/assets/js/15.8ba1c321.js"><link rel="prefetch" href="/assets/js/16.f7f0d34c.js"><link rel="prefetch" href="/assets/js/17.aac0bf62.js"><link rel="prefetch" href="/assets/js/18.2e2fe306.js"><link rel="prefetch" href="/assets/js/19.aee304b3.js"><link rel="prefetch" href="/assets/js/20.86a73bc1.js"><link rel="prefetch" href="/assets/js/21.8992c972.js"><link rel="prefetch" href="/assets/js/22.0a78500a.js"><link rel="prefetch" href="/assets/js/23.06342909.js"><link rel="prefetch" href="/assets/js/24.06fd96a3.js"><link rel="prefetch" href="/assets/js/25.00664d4e.js"><link rel="prefetch" href="/assets/js/26.c3d4b548.js"><link rel="prefetch" href="/assets/js/27.3c6927ad.js"><link rel="prefetch" href="/assets/js/28.74498c0b.js"><link rel="prefetch" href="/assets/js/29.aae1a826.js"><link rel="prefetch" href="/assets/js/3.4d2bdca7.js"><link rel="prefetch" href="/assets/js/30.c7732a2c.js"><link rel="prefetch" href="/assets/js/31.20403043.js"><link rel="prefetch" href="/assets/js/33.8610da11.js"><link rel="prefetch" href="/assets/js/4.d7b1015b.js"><link rel="prefetch" href="/assets/js/5.ff87de2e.js"><link rel="prefetch" href="/assets/js/6.0e91e688.js"><link rel="prefetch" href="/assets/js/7.ba30e213.js"><link rel="prefetch" href="/assets/js/8.35122549.js"><link rel="prefetch" href="/assets/js/9.081b18e5.js">
    <link rel="stylesheet" href="/assets/css/0.styles.6834c255.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="ant-row"><div class="sidebar-button"><i aria-label="icon: bars" class="anticon anticon-bars"><svg viewBox="0 0 1024 1024" focusable="false" data-icon="bars" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M912 192H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 284H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 284H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM104 228a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm0 284a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm0 284a56 56 0 1 0 112 0 56 56 0 1 0-112 0z"></path></svg></i> <span></span></div> <div class="ant-col ant-col-xs-24 ant-col-sm-24 ant-col-md-6 ant-col-lg-5 ant-col-xl-5 ant-col-xxl-4"><a href="/" class="router-link-active no-logo home-link"><!----> <span class="site-name">CatchAdmin 官网</span></a> <div class="search-box mobile-search"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div></div> <div class="ant-col ant-col-xs-0 ant-col-sm-0 ant-col-md-18 ant-col-lg-19 ant-col-xl-19 ant-col-xxl-20"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><ul role="menu" id="nav" class="ant-menu ant-menu-horizontal ant-menu-root ant-menu-light"><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/" class="router-link-active">
          🏠首页
        </a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/docs/">
          📖文档
        </a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item ant-menu-item-selected"><a href="/laravel/" class="router-link-active">
          📖Laravel
        </a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/faq/">
          🤔FAQ
        </a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/donate/">
          🎉赞助名单
        </a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>
          🚀仓库地址
        </span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="visibility:hidden;position:absolute;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li></ul> <!----></nav></div></div> <!----></header> <aside class="sidebar"><div><div class="ads"><div id="ads_1"><img src="https://cover.kancloud.cn/akasishikelu/thinkphp6!middle"> <span title="基于 catchadmin 的 Thinkphp 6.0 企业级后台管理开发&amp;源码分析">基于 catchadmin 的 Thinkphp 6.0 企业级后台管理开发&amp;源码分析</span></div></div> <div role="separator" id="reset-margin" class="ant-divider ant-divider-horizontal ant-divider-dashed"></div></div> <ul class="sidebar-links"><li><a href="/laravel/" aria-current="page" title="介绍" class="sidebar-link">介绍</a></li><li><a href="/laravel/install.html" title="项目安装" class="sidebar-link">项目安装</a></li><li><a href="/laravel/module.html" title="模块" class="sidebar-link">模块</a></li><li><a href="/laravel/model.html" title="模型" class="sidebar-link">模型</a></li><li><a href="/laravel/console.html" title="命令" class="sidebar-link">命令</a></li><li><a href="/laravel/form.html" title="表单" class="sidebar-link">表单</a></li><li><a href="/laravel/table.html" aria-current="page" title="表格组件" class="active sidebar-link">表格组件</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/laravel/table.html#表格组件" title="表格组件" class="sidebar-link">表格组件</a></li><li class="sidebar-sub-header"><a href="/laravel/table.html#头部" title="头部" class="sidebar-link">头部</a></li><li class="sidebar-sub-header"><a href="/laravel/table.html#表格" title="表格" class="sidebar-link">表格</a></li></ul></li><li><a href="/laravel/macros.html" title="扩展方法" class="sidebar-link">扩展方法</a></li><li><a href="/laravel/excel.html" title="Excel" class="sidebar-link">Excel</a></li><li><a href="/laravel/issue.html" title="常见问题" class="sidebar-link">常见问题</a></li></ul></aside> <main class="page"> <div class="theme-antdocs-content content__default"><h2 id="表格组件"><a href="#表格组件" class="header-anchor">#</a> 表格组件</h2> <div class="custom-block warning"><p class="custom-block-title">WARNING</p> <p>表格组件目前可以完成正常的 85% 的操作，部分需求请回归正常的页面开发。再使用之前，请熟悉 element table 组件。
目前基础模块有大量案例可供参考。具体查看代码。有问题请去<a href="https://bbs.catchadmin.com/" target="_blank" rel="noopener noreferrer">论坛提问<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>，请不要在群里问，重复的问题太多。</p></div> <h2 id="头部"><a href="#头部" class="header-anchor">#</a> 头部</h2> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$table</span><span class="token operator">-&gt;</span><span class="token function">header</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'ID'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'id'</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token class-name return-type">HeaderItem</span>
</code></pre></div><h3 id="设置多选"><a href="#设置多选" class="header-anchor">#</a> 设置多选</h3> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$headerItem</span><span class="token operator">-&gt;</span><span class="token function">selection</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h3 id="设置宽度"><a href="#设置宽度" class="header-anchor">#</a> 设置宽度</h3> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$headerItem</span><span class="token operator">-&gt;</span><span class="token function">width</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$width</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h3 id="设置居中"><a href="#设置居中" class="header-anchor">#</a> 设置居中</h3> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$headerItem</span><span class="token operator">-&gt;</span><span class="token function">alignCenter</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h3 id="设置居右"><a href="#设置居右" class="header-anchor">#</a> 设置居右</h3> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$headerItem</span><span class="token operator">-&gt;</span><span class="token function">alignRight</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h3 id="设置可排序"><a href="#设置可排序" class="header-anchor">#</a> 设置可排序</h3> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$headerItem</span><span class="token operator">-&gt;</span><span class="token function">sortable</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h3 id="导出"><a href="#导出" class="header-anchor">#</a> 导出</h3> <blockquote><p>导出方法是回调函数，它允许导出时候对字段进行数据处理</p></blockquote> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$headerItem</span><span class="token operator">-&gt;</span><span class="token function">export</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token variable">$value</span><span class="token punctuation">,</span> <span class="token variable">$iitem</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token variable">$value</span> <span class="token operator">==</span> <span class="token class-name static-context">UsersModel</span><span class="token operator">::</span><span class="token constant">ENABLE</span> <span class="token operator">?</span> <span class="token string single-quoted-string">'正常'</span> <span class="token punctuation">:</span> <span class="token string single-quoted-string">'关闭'</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h3 id="设置操作-column"><a href="#设置操作-column" class="header-anchor">#</a> 设置操作（column）</h3> <blockquote><p>设置更新和删除操作</p></blockquote> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$headerItem</span><span class="token operator">-&gt;</span><span class="token function">actions</span><span class="token punctuation">(</span><span class="token punctuation">[</span>
    <span class="token class-name static-context">Action</span><span class="token operator">::</span><span class="token function">update</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token class-name static-context">Action</span><span class="token operator">::</span><span class="token function">delete</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre></div><h3 id="固定列"><a href="#固定列" class="header-anchor">#</a> 固定列</h3> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$headerItem</span><span class="token operator">-&gt;</span><span class="token function">fixed</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h3 id="隐藏列"><a href="#隐藏列" class="header-anchor">#</a> 隐藏列</h3> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$headerItem</span><span class="token operator">-&gt;</span><span class="token function">hidden</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h3 id="不导出"><a href="#不导出" class="header-anchor">#</a> 不导出</h3> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$headerItem</span><span class="token operator">-&gt;</span><span class="token function">dontImport</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h3 id="关联字段"><a href="#关联字段" class="header-anchor">#</a> 关联字段</h3> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$headerItem</span><span class="token operator">-&gt;</span><span class="token function">relations</span><span class="token punctuation">(</span><span class="token variable">$fields</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><p>当访问用户列表的时候，如果需要查询用户关联的角色，那么就可以使用该方法查询出角色的字段.</p> <p>首先在 <code>UsersModel</code> 定义了关联关系</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function">roles</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// 多对多的关系</span>
<span class="token punctuation">}</span>
</code></pre></div><div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$headerItem</span><span class="token operator">-&gt;</span><span class="token function">prop</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'roles'</span><span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">label</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'角色'</span><span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">relations</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'id'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><p>这里的 <code>prop</code> 的参数就是代表 用户模型的 <code>roles()</code> 方法的名称，也就是关联关系的名称，<code>relations()</code> 里面就是查询的字段</p> <h3 id="table-列的插槽"><a href="#table-列的插槽" class="header-anchor">#</a> table 列的插槽</h3> <p>这些组件提供了列的数据可动态操作，除了内置的组件，自己也可以自定义列的插槽组件</p> <ul><li>component 组件</li></ul> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$headerItem</span><span class="token operator">-&gt;</span><span class="token function">component</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$updateField</span> <span class="token operator">=</span> <span class="token string single-quoted-string">''</span><span class="token punctuation">,</span> <span class="token variable">$options</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre></div><ul><li>switch 组件</li></ul> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$headerItem</span><span class="token operator">-&gt;</span><span class="token keyword">switch</span><span class="token punctuation">(</span><span class="token keyword type-hint">array</span> <span class="token variable">$options</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token variable">$updateFields</span> <span class="token operator">=</span> <span class="token constant">null</span><span class="token punctuation">)</span>
</code></pre></div><div class="custom-block tip"><p class="custom-block-title">TIP</p> <p>可以使用 Form::options()-&gt;add('文字', 1)-&gt;render()</p></div> <ul><li>edit 组件</li></ul> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$headerItem</span><span class="token operator">-&gt;</span><span class="token function">edit</span><span class="token punctuation">(</span><span class="token variable">$updateFields</span> <span class="token operator">=</span> <span class="token constant">null</span><span class="token punctuation">)</span>
</code></pre></div><ul><li>eidtNumber 组件</li></ul> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$headerItem</span><span class="token operator">-&gt;</span><span class="token function">editNumber</span><span class="token punctuation">(</span><span class="token variable">$updateFields</span> <span class="token operator">=</span> <span class="token constant">null</span><span class="token punctuation">)</span>
</code></pre></div><ul><li>select 组件</li></ul> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$headerItem</span><span class="token operator">-&gt;</span><span class="token function">select</span><span class="token punctuation">(</span><span class="token keyword type-hint">array</span> <span class="token variable">$options</span><span class="token punctuation">,</span> <span class="token variable">$updateFields</span> <span class="token operator">=</span> <span class="token constant">null</span><span class="token punctuation">)</span>
</code></pre></div><ul><li>preview 组件（预览组件）</li></ul> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$headerItem</span><span class="token operator">-&gt;</span><span class="token function">preview</span><span class="token punctuation">(</span><span class="token variable">$field</span> <span class="token operator">=</span> <span class="token constant">null</span><span class="token punctuation">)</span>
</code></pre></div><ul><li>下载 组件</li></ul> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$headerItem</span><span class="token operator">-&gt;</span><span class="token function">download</span><span class="token punctuation">(</span><span class="token variable">$field</span> <span class="token operator">=</span> <span class="token constant">null</span><span class="token punctuation">)</span>
</code></pre></div><ul><li>跳转 组件</li></ul> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$headerItem</span><span class="token operator">-&gt;</span><span class="token function">url</span><span class="token punctuation">(</span><span class="token variable">$field</span> <span class="token operator">=</span> <span class="token constant">null</span><span class="token punctuation">)</span>
</code></pre></div><ul><li>复制 组件</li></ul> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$headerItem</span><span class="token operator">-&gt;</span><span class="token function">copy</span><span class="token punctuation">(</span><span class="token variable">$field</span> <span class="token operator">=</span> <span class="token constant">null</span><span class="token punctuation">)</span>
</code></pre></div><h3 id="可以直接使用的快捷方法"><a href="#可以直接使用的快捷方法" class="header-anchor">#</a> 可以直接使用的快捷方法</h3> <ul><li>设置<code>ID</code>列<div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$table</span><span class="token operator">-&gt;</span><span class="token function">id</span><span class="token punctuation">(</span><span class="token keyword type-hint">bool</span> <span class="token variable">$selection</span> <span class="token operator">=</span> <span class="token constant boolean">true</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$field</span> <span class="token operator">=</span> <span class="token string single-quoted-string">''</span><span class="token punctuation">)</span>
</code></pre></div></li> <li>设置开始时间<div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$table</span><span class="token operator">-&gt;</span><span class="token function">createdAt</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div></li> <li>设置更新时间</li></ul> <div class="language-php extra-class"><pre class="language-php"><code>  <span class="token variable">$table</span><span class="token operator">-&gt;</span><span class="token function">updatedAt</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><ul><li>设置状态列<div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$table</span><span class="token operator">-&gt;</span><span class="token function">status</span><span class="token punctuation">(</span><span class="token keyword type-hint">bool</span> <span class="token variable">$switch</span> <span class="token operator">=</span> <span class="token constant boolean">true</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$field</span> <span class="token operator">=</span> <span class="token string single-quoted-string">'status'</span><span class="token punctuation">)</span>
</code></pre></div></li> <li>设置排序列<div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$table</span><span class="token operator">-&gt;</span><span class="token function">sorts</span><span class="token punctuation">(</span><span class="token keyword type-hint">bool</span> <span class="token variable">$edit</span> <span class="token operator">=</span> <span class="token constant boolean">false</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$field</span> <span class="token operator">=</span> <span class="token string single-quoted-string">'sort'</span><span class="token punctuation">)</span>
</code></pre></div></li> <li>设置操作列（默认更新+删除）<div class="language-php extra-class"><pre class="language-php"><code>  <span class="token variable">$table</span><span class="token operator">-&gt;</span><span class="token function">operations</span><span class="token punctuation">(</span><span class="token keyword type-hint">array</span> <span class="token variable">$actions</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre></div></li></ul> <h2 id="表格"><a href="#表格" class="header-anchor">#</a> 表格</h2> <h3 id="操作"><a href="#操作" class="header-anchor">#</a> 操作</h3> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$table</span><span class="token operator">-&gt;</span><span class="token function">actions</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token variable">$table</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token variable">$table</span><span class="token operator">-&gt;</span><span class="token function">store</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">// 导出按钮</span>
    <span class="token variable">$table</span><span class="token operator">-&gt;</span><span class="token function">export</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'users'</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre></div><h3 id="设置路由-后端"><a href="#设置路由-后端" class="header-anchor">#</a> 设置路由（后端）</h3> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$table</span><span class="token operator">-&gt;</span><span class="token function">apiRoute</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'users'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h3 id="默认搜索"><a href="#默认搜索" class="header-anchor">#</a> 默认搜索</h3> <blockquote><p>如果表格需要默认搜索条件，那么可以使用</p></blockquote> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$table</span><span class="token operator">-&gt;</span><span class="token function">where</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token variable">$model</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token variable">$model</span><span class="token operator">-&gt;</span><span class="token function">where</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'condition'</span><span class="token punctuation">,</span> <span class="token variable">$value</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre></div><h3 id="查询后"><a href="#查询后" class="header-anchor">#</a> 查询后</h3> <blockquote><p>如果需要对表格的列表数据在返回前做一次处理，那么可以使用 <code>dealWithList</code></p></blockquote> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$table</span><span class="token operator">-&gt;</span><span class="token function">dealWithList</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token variable">$data</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token comment">// 这里处理数据</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre></div><h3 id="数据权限"><a href="#数据权限" class="header-anchor">#</a> 数据权限</h3> <p>首先需要在使用的模型中引入 <code>\CatchAdmin\Permissions\Models\DataRangeScopeTrait</code> trait，然后使用</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$table</span><span class="token operator">-&gt;</span><span class="token function">useDataRange</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><p>就可以实现数据权限功能了</p> <h3 id="树形-table"><a href="#树形-table" class="header-anchor">#</a> 树形 table</h3> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$table</span><span class="token operator">-&gt;</span><span class="token function">toTreeTable</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><blockquote><p>如果树形结构需要默认展开，那么使用</p></blockquote> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$table</span><span class="token operator">-&gt;</span><span class="token function">toTreeTable</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">expandAll</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><h3 id="设置新增的-dialog-宽度"><a href="#设置新增的-dialog-宽度" class="header-anchor">#</a> 设置新增的 Dialog 宽度</h3> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$table</span><span class="token operator">-&gt;</span><span class="token function">dialogWidth</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'35%'</span><span class="token punctuation">)</span>
</code></pre></div><h3 id="表格排序"><a href="#表格排序" class="header-anchor">#</a> 表格排序</h3> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$table</span><span class="token operator">-&gt;</span><span class="token function">sort</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token variable">$query</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token comment">// 这里使用排序</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre></div><h3 id="绑定模式"><a href="#绑定模式" class="header-anchor">#</a> 绑定模式</h3> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$table</span><span class="token operator">-&gt;</span><span class="token function">withBind</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><div class="custom-block tip"><p class="custom-block-title">TIP</p> <p>使用该方法之后，前端 <code>catch-table</code> 可以更加简洁的使用。注意看之后前端的说明</p></div> <h3 id="设置强制更新组件"><a href="#设置强制更新组件" class="header-anchor">#</a> 设置强制更新组件</h3> <div class="language-php extra-class"><pre class="language-php"><code>  table<span class="token operator">-&gt;</span><span class="token function">forceUpdate</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><h3 id="导出-2"><a href="#导出-2" class="header-anchor">#</a> 导出</h3> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$table</span><span class="token operator">-&gt;</span><span class="token function">export</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$exportRoute</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h3 id="搜索"><a href="#搜索" class="header-anchor">#</a> 搜索</h3> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$table</span><span class="token operator">-&gt;</span><span class="token function">search</span><span class="token punctuation">(</span><span class="token punctuation">[</span>
    <span class="token class-name static-context">Search</span><span class="token operator">::</span><span class="token function">like</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h3 id="search-搜索组件"><a href="#search-搜索组件" class="header-anchor">#</a> Search 搜索组件</h3> <ul><li><p>设置 <code>%模糊</code> 搜索</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Search</span><span class="token operator">::</span><span class="token function">startLike</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token variable">$title</span><span class="token punctuation">)</span>
</code></pre></div></li> <li><p>设置<code>%模糊%</code>搜索</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Search</span><span class="token operator">::</span><span class="token function">like</span><span class="token punctuation">(</span><span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token variable">$placeholder</span><span class="token punctuation">)</span>
</code></pre></div></li> <li><p>设置<code>模糊%</code>搜索</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Search</span><span class="token operator">::</span><span class="token function">endLike</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token variable">$title</span><span class="token punctuation">)</span>
</code></pre></div></li> <li><p>设置 name, 默认 <code>name</code> 搜索</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Search</span><span class="token operator">::</span><span class="token function">name</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div></li> <li><p>设置 status, 默认 <code>status</code> 状态搜索</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Search</span><span class="token operator">::</span><span class="token function">status</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div></li> <li><p>设置 startAt, 默认 <code>start_at</code> 开始时间搜索</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Search</span><span class="token operator">::</span><span class="token function">startAt</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span> <span class="token operator">=</span> <span class="token string single-quoted-string">'start_at'</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span> <span class="token operator">=</span> <span class="token string single-quoted-string">'开始时间'</span><span class="token punctuation">)</span>
</code></pre></div></li> <li><p>设置 endAt, 默认 <code>end_at</code> 结束时间搜索</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Search</span><span class="token operator">::</span><span class="token function">endAt</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span> <span class="token operator">=</span> <span class="token string single-quoted-string">'end_at'</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span> <span class="token operator">=</span> <span class="token string single-quoted-string">'结束时间'</span><span class="token punctuation">)</span>
</code></pre></div></li> <li><p>设置最小值</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Search</span><span class="token operator">::</span><span class="token function">min</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token variable">$title</span><span class="token punctuation">)</span>
</code></pre></div></li> <li><p>设置最大值</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Search</span><span class="token operator">::</span><span class="token function">max</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token variable">$title</span><span class="token punctuation">)</span>
</code></pre></div></li></ul> <div class="custom-block tip"><p class="custom-block-title">TIP</p> <p><code>Form</code> 组件的方法， <code>Search</code> 组件一样可以使用。根本上来说，<code>Search</code> 组件是由 <code>Form</code> 组件包装的</p></div></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/catch-admin/document/edit/master/docs/laravel/table.md" target="_blank" rel="noopener noreferrer">在 Github 编辑此页</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev"><a href="/laravel/form.html" class="prev"><i aria-label="icon: left" class="anticon anticon-left"><svg viewBox="64 64 896 896" focusable="false" data-icon="left" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M724 218.3V141c0-6.7-7.7-10.4-12.9-6.3L260.3 486.8a31.86 31.86 0 0 0 0 50.3l450.8 352.1c5.3 4.1 12.9.4 12.9-6.3v-77.3c0-4.9-2.3-9.6-6.1-12.6l-360-281 360-281.1c3.8-3 6.1-7.7 6.1-12.6z"></path></svg></i>
        表单
      </a></span> <span class="next"><a href="/laravel/macros.html">
        扩展方法
        <i aria-label="icon: right" class="anticon anticon-right"><svg viewBox="64 64 896 896" focusable="false" data-icon="right" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M765.7 486.8L314.9 134.7A7.97 7.97 0 0 0 302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 0 0 0-50.4z"></path></svg></i></a></span></p></div> </main> <!----></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.d0396f44.js" defer></script><script src="/assets/js/2.1cef47df.js" defer></script><script src="/assets/js/32.7b8e9cfe.js" defer></script>
  </body>
</html>